using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.IServices.QualityAssurance;
using System.Threading.Tasks;
using VOL.Core.Controllers.Basic;
using VOL.Core.Filters;
using VOL.Core.Utilities.Response;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.Core;
using VOL.Entity.DomainModels.QualityAssurance;

namespace VOL.WebApi.Controllers.MyMES
{
    /// <summary>
    /// 出货检查管理控制器
    /// </summary>
    [Route("api/OutProductCheck")]
    [ApiController]
    [AllowAnonymous] // 允许匿名访问
    [PermissionTable(Name = "OutProductCheck")]
    public class OutProductCheckController : ApiBaseController<IOutProductCheckService>
    {
        private readonly IOutProductCheckService _outProductCheckService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="outProductCheckService">出货检查服务</param>
        public OutProductCheckController(IOutProductCheckService outProductCheckService)
            : base(outProductCheckService)
        {
            _outProductCheckService = outProductCheckService;
        }

        /// <summary>
        /// 获取出货检查记录列表
        /// </summary>
        /// <param name="dto">查询参数</param>
        /// <returns>出货检查记录列表（分页）</returns>
        [HttpPost("GetOutProductCheckList")]
        public async Task<ActionResult> GetOutProductCheckList([FromBody] GetOutProductCheckDto dto)
        {
            return Json(await _outProductCheckService.GetOutProductCheckList(dto));
        }

        /// <summary>
        /// 添加出货检查记录
        /// </summary>
        /// <param name="outProductCheck">出货检查记录实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("AddOutProductCheck")]
        public async Task<WebResponseContent> AddOutProductCheck([FromBody] OutProductCheck outProductCheck)
        {
            return await _outProductCheckService.AddOutProductCheck(outProductCheck);
        }

        /// <summary>
        /// 更新出货检查记录
        /// </summary>
        /// <param name="outProductCheck">出货检查记录实体</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdOutProductCheck")]
        public async Task<WebResponseContent> UpdOutProductCheck([FromBody] OutProductCheck outProductCheck)
        {
            return await _outProductCheckService.UpdOutProductCheck(outProductCheck);
        }

        /// <summary>
        /// 删除出货检查记录
        /// </summary>
        /// <param name="ids">记录ID列表，逗号分隔</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelOutProductCheck")]
        public async Task<WebResponseContent> DelOutProductCheck([FromQuery] string ids)
        {
            return await _outProductCheckService.DelOutProductCheck(ids);
        }
        
        /// <summary>
        /// 获取客户列表
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>客户列表(分页)</returns>
        [HttpPost("GetCustomerList")]
        public async Task<ActionResult> GetCustomerList([FromBody] GetCustomerDto2 dto)
        {
            return Json(await _outProductCheckService.GetCustomerList(dto));
        }
        
        /// <summary>
        /// 获取物料分类列表
        /// </summary>
        /// <returns>带有父子级关系的物料分类树形结构</returns>
        [HttpGet("GetMaterialCatalogList")]
        public async Task<WebResponseContent> GetMaterialCatalogList()
        {
            return await _outProductCheckService.GetMaterialCatalogList();
        }
        
        /// <summary>
        /// 获取物料列表
        /// </summary>
        /// <param name="materialCode">物料编码</param>
        /// <param name="materialName">物料名称</param>
        /// <param name="classifyName">分类名称</param>
        /// <returns>物料列表</returns>
        [HttpPost("GetMaterialList")]
        public async Task<PageGridData<MaterialProduct>> GetMaterialList([FromBody]GetMaterialListDto dto)
        {
            return await _outProductCheckService.GetMaterialList(dto);
        }

    }
} 